<?php 
namespace  Manager\Controller;
use Org\Util\Ueditor;
use Think\Page;
use Think\Upload;
use Think\Image;
/**
* ==============================================
* URL：http://www.liuhuanhui.cn
* ==============================================
* @date：2014-10-21
* @time：下午9:37:33
* @author：liuhuanhui
* @encoding：UTF-8
*/
class SayController extends  AuthController
{
		/**
		 * 首页
		 */
		function index()
		{
			//分页获取数据
			$say=M('says');
			$page=new Page($say->count(),5);
			$this->pageShow=$page->show();
			$this->says=$say->order('date desc')->limit($page->firstRow,$page->listRows)->select();
			$this->display();
		}
		/**
		 * 写说说
		 */
		function create()
		{
			$this->display();
		}
		/**
		 * 发表说说处理
		 */
		function createHandle()
		{
			if(!empty($_FILES['file']['name']))
			{
				/********SAE*******/
				$upload=new Upload();
				$upload->savePath='/say_images/';
				$upload->autoSub=false;
				$upload->replace=true;
				$info=$upload->uploadOne($_FILES['file']);
				
				//生成缩略图
				$s = new \SaeStorage();
				$f = new \SaeFetchurl();
				$img= new \SaeImage();
				$first_img_pic= $info['url'];
				$img_data= $f->fetch( $first_img_pic);
				$img->setData($img_data);
				$img->resize(300);// 等比缩放
				$Smallimg= $img->exec(); // 执行处理并返回处理后的二进制数据
				$s->write('uploads',"say_images/".$info['savename'],$Smallimg, -1);
				if(!$info||!$s)
				{
					$this->error('照片Show上传失败！');
				}
				
				$_POST['image']=$info['savename'];
				
				/* LINUX AND WINDOWS
				$fileName='Say_'.time().'.'.pathinfo($_FILES['file']['name'],PATHINFO_EXTENSION);
				$savePath='uploads/say_images/'.$fileName;
				$image = new Image();
				$image->open($_FILES['file']['tmp_name']);// 按照原图的比例生成一个最大为150*150的缩略图并保存为thumb.jpg
				$result=$image->thumb(300,300)->save($savePath);
				if (!$result)
					$this->error('图片上传失败！');
				$_POST['image']=$fileName;*/
			}
			$say=D('Says');
				if ($say->create())
				{
					if($say->add())
						$this->success('发表说说成功！',U('index'));
					else
						$this->error('修发表说说失败！');
				}
		}
		/**
		 * 实例化编辑器
		 */
		function ueditor()
		{
			$data =new Ueditor();
			echo $data->output();
		}
		/**
		 * 删除说说
		 */
		function delete()
		{
			if(M('says')->delete(I('id')))
				$this->success('删除说说成功！',U('index'));
			else
				$this->error('删除表说说失败！');
		}
}
?>